<template>
  <div>
    <el-switch
      v-model="cq"
      active-text="开启数据切换"
      inactive-text="关闭数据切换"
      :active-value="true"
      :inactive-value="false"
      @change="loop"
    />

    <div ref="radar" class="radar" />
  </div>
</template>

<script>

export default {
  data () {
    return {
      cq: false,
      opt: {
        tooltip: {},
        // titel: { triggerEvent: true },
        radar: {
          // shape: 'circle',
          // 雷达图数据指标(数据项或属性)
          indicator: [
            { name: '工作效率', max: 100 },
            { name: '考勤', max: 100 },
            { name: '积极性', max: 100 },
            { name: '帮助同事', max: 100 },
            { name: '自主学习', max: 100 },
            { name: '正确率', max: 100 }
          ]
        },
        series: [{
          type: 'radar',
          data: []
        }]

      }

    }
  },
  mounted () {
    this.drawRadar()
  },
  beforeDestroy () {
    clearInterval(this.st)
  },
  methods: {
    loop () {
      if (this.st) {
        clearInterval(this.st)
        this.st = null
        return
      }
      this.st = setInterval(this.change, 1000)
    },
    change () {
      const data = []
      for (let index = 0; index < 4; index++) {
        const per = { value: [], name: `${index}` }
        for (let j = 0; j < 6; j++) {
          per.value.push(Math.floor(Math.random() * 100 + 1))
        }
        data.push(per)
      }
      // 绘制图标
      // 该数据
      this.opt.series[0].data = data
      this.myChart.setOption(this.opt)
    },
    drawRadar () {
      // 基于准备好的dom，初始化echarts实例
      this.myChart = this.echarts.init(this.$refs.radar)
      // 绘制图标1 准备对应图标配置文件2 调用setOption传入配置绘制
      // 绘制的配置配置文件
      this.opt.series[0].data = [
        {
          value: [10, 1, 100, 5, 100, 0],
          name: '张三'
        },
        {
          value: [50, 50, 50, 50, 50, 10],
          name: '李四'
        },
        {
          value: [1, 1, 60, 5, 50, 0],
          name: '王五'
        },
        {
          value: [30, 20, 60, 70, 40, 10],
          name: '钱六'
        }
      ]
      this.myChart.setOption(this.opt)
    }
  }
}
</script>

<style lang="scss" scoped>
.radar {
  width: 100%;
  height: 400px;
}
</style>
